//
//  PartnerTableViewCell.m
//  JiFengDaRen
//
//  Created by shouhan on 2018/6/8.
//  Copyright © 2018年 陈永发. All rights reserved.
//

#import "PartnerTableViewCell.h"
#import "PartnerModel.h"

@interface PartnerTableViewCell()

@property (nonatomic, strong) UILabel *phoneLabel;

@property (nonatomic, strong) UILabel * type;

@property (nonatomic, strong) UILabel * peopleNum;


@property (nonatomic, strong) UIView * line;

@end

@implementation PartnerTableViewCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self initUI];
    }
    return self;
}


+ (instancetype)tableViewCellWithTableView:(UITableView *)tableView
{
    static NSString * cellIndentfile = @"PartnerTableViewCell";
    PartnerTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellIndentfile];
    
    if (!cell) {
        cell = [[PartnerTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIndentfile];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
}

- (void)initUI{
    self.phoneLabel = [UILabel new];
    self.phoneLabel.textColor = [UIColor colorWithHexString:@"#333333"];
    self.phoneLabel.font = KSHSystemFont(14);
    [self.contentView addSubview:self.phoneLabel];
    
    self.type = [UILabel new];
    self.type.textColor = [UIColor colorWithHexString:@"#666666"];
    self.type.font = KSHSystemFont(14);
    self.type.textAlignment = NSTextAlignmentRight;
    [self.contentView addSubview:self.type];
    
    self.peopleNum = [UILabel new];
    self.peopleNum.textColor = [UIColor colorWithHexString:@"#666666"];
    self.peopleNum.font = KSHSystemFont(14);
    self.peopleNum.textAlignment = NSTextAlignmentRight;
    [self.contentView addSubview:self.peopleNum];
    
    self.arrow = [UIImageView new];
    self.arrow.image = [UIImage imageNamed:@"jmarrow"];
    [self.contentView addSubview:self.arrow];
    
    self.line = [UIView new];
    self.line.backgroundColor = [UIColor colorWithHexString:@"#E0E0E0"];
    [self.contentView addSubview:self.line];
    
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
    [self.phoneLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(__I6Width(16));
        make.centerY.equalTo(self.contentView);
    }];
    
    [@[self.type,self.peopleNum] mas_distributeViewsAlongAxis:MASAxisTypeVertical withFixedSpacing:5 leadSpacing:10 tailSpacing:10];
    
    [@[self.type,self.peopleNum] mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView).offset(-__I6Width(16));
    }];
    
    [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.right.equalTo(self.contentView);
        make.height.mas_offset(.5);
    }];
    
    [self.arrow mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView);
        make.right.equalTo(self.contentView).offset(-__I6Width(16));
    }];
    
}

- (void)setModel:(PartnerModel *)model{
    _model = model;
    
    self.phoneLabel.text = [Tool numberSuitScanf:model.phone];
    self.peopleNum.text = [NSString stringWithFormat:@"邀请：%@人",model.inviter_count];
    if (model.is_agent == YES) {
        self.type.text = @"代理商";
    }else{
        self.type.text = @"普通客户";
    }


}

- (void)getCellIndex:(NSInteger)index{
    if (index == 0) {
        self.arrow.hidden = NO;
        self.phoneLabel.text = @"查询交易记录";
        self.type.hidden = YES;
        self.peopleNum.hidden = YES;
    }else{
        self.arrow.hidden = YES;
        self.type.hidden = NO;
        self.peopleNum.hidden = NO;
    }
}

@end
